package com.clstu.draw.tankgame;

import javax.swing.*;//定义坦克的绘图区
import java.awt.*;

public class MyPanel extends JPanel {//用画板来画坦克，镶嵌到画框里面才可以显示
    Hero hero = null;
    public MyPanel(){
        hero=new Hero(100,100);//初始化自己的坦克
    }


    @Override
    public void paint(Graphics g) {
        super.paint(g);//初始化画笔g
        g.fillRect(0,0,1000,750);
        drawTank(hero.getX(),hero.getY(),g,1,0);
        drawTank(hero.getX()+80,hero.getY(),g,1,1);
        drawTank(hero.getX()+80,hero.getY(),g,0,1);
    }

    /**
     *
     * @param x 横坐标
     * @param y 纵坐标
     * @param g 画笔
     * @param direct 方向
     * @param type 类型
     */
    private void drawTank(int x,int y,Graphics g,int direct,int type){//根据参数画出坦克，通过被paint调用画出
        switch (type){
            case 0:
                g.setColor(Color.cyan);
                break;
            case 1:
                g.setColor(Color.yellow);
                break;
        }
        switch (direct){
            case 1:
                g.fill3DRect(x,y,10,60,false);
                g.fill3DRect(x+30,y,10,60,false);
                g.fill3DRect(x+10,y+10,20,40,false);
                g.drawOval(x+10,y+20,20,20);
                g.drawLine(x+20,y,x+20,y+30);
                break;
            default:
                System.out.println("还没有设计出来~~");
                break;
        }
    }


}
